package com.controller;

import com.model.LOG;
import com.model.MyEcharts1;
import com.model.MyEcharts2;
import com.server.MylogService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "1228作业测试")
@RestController
@RequestMapping("/mylog")


public class logController {

    @Autowired
    private MylogService mylogService;

    @CrossOrigin
    @RequestMapping(value = "/addLog", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public int addLog(@RequestBody LOG myLog){
        System.out.println("进入日志添加方法");
        return mylogService.addLog(myLog);
    }

    @CrossOrigin
    @RequestMapping(value = "/getLog", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public LOG getLog(int userid){
        System.out.println("进入根据主键查找日志信息, 主键为: " + userid);
        return mylogService.getLog(userid);
    }

    @CrossOrigin
    @RequestMapping(value = "/updateLog", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public int updateMylog(@RequestBody LOG myLog){
        System.out.println("进入日志修改方法, 修改的主键为: " + myLog.getUserid());
        return mylogService.updateMylog(myLog);
    }

    @CrossOrigin
    @RequestMapping(value = "/deleteLog", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public int deleteMylog(int userid){
        System.out.println("进入删除日志信息, 主键为: " + userid);
        return mylogService.deleteMylog(userid);
    }

    @CrossOrigin
    @RequestMapping(value = "/getAll", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public List<LOG> getAllMylogs(@RequestBody LOG myLog){
        System.out.println("进入日志查询方法");
        System.out.println(myLog.getIPaddress()+"=======");
        return mylogService.getAllMylogs(myLog);
    }

    @CrossOrigin
    @RequestMapping(value = "/getIdAndTime", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public LOG getIdAndTime(int userid) {
        System.out.println("进入查询用户ID以及操作时间方法");
        return mylogService.getIdAndTime(userid);
    }

    @CrossOrigin
    @RequestMapping(value = "/getEcharts", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public List<MyEcharts1> getEcharts(@RequestBody LOG myLog){
        System.out.println("进入日志分析方法");
        System.out.println(myLog.getIPaddress());
        List<MyEcharts1> myEchart1s =mylogService.EchartsMyLogStart(myLog);
        System.out.println(myEchart1s.size());
        return myEchart1s;
    }

    @CrossOrigin
    @RequestMapping(value = "/getWeekTrend", produces = "application/json;charset=utf-8", method = RequestMethod.PUT)
    public List<MyEcharts2> getWeeklyTrend(@RequestBody LOG myLog){
        System.out.println("进入每周线形图走向方法");
        System.out.println(myLog.getUserid());
        List<MyEcharts2> myEcharts2 =mylogService.EchartsWeeklyTrend(myLog);
        System.out.println(myEcharts2.size());
        return myEcharts2;
    }
}
